<% extends 'public/base.html'%>
<% block content %>
  <div class="main-news">
      <div class="layui-container">
          <div class="layui-row layui-col-space20" id="main_news_list"></div>
      </div>
      <div id="newsPage"></div>
      <input type='hidden' id='news_count' value='<< news_count >>'>
  </div>
<% endblock %>
<% block script%>
function reset_span_text(){
    $(".main-news").find(".content").each(function(){
      var span = $(this).find(".detail").children("span")
      ,spanTxt = span.html();
      if(document.body.clientWidth > 463){
        span.html(spanTxt);
      }else{
        span.html(span.html().substring(0, 42)+ '...')
      };
      $(window).resize(function(){
        if(document.body.clientWidth > 463){
          span.html(spanTxt);
        }else{
          span.html(span.html().substring(0, 42)+ '...')
        };
      });
    });
  }
  laypage.render({
        elem: 'newsPage'
        , count: $('#news_count').val()
        ,limits: [10, 20, 30, 40, 50]
        ,layout:['count','prev', 'page', 'next','limit','skip']
        ,jump: function(obj, first){
         $("#main_news_list").html('');
          $.ajax({
            url: "/news/list",
            method:'post',
            type:'json',
            data:JSON.stringify({page:obj.curr,limit: obj.limit}),
            contentType: 'json',
            success:function(res){
                if(res.success==true){
                  if(res.result.length>0) {
                    $.each(res.result, function (index, item) {
                      var html = '<div class="layui-col-lg6 content"><div><div class="news-img"><a href="/news/' + item.id + '"><img src="https://oss.zimu.website/zimu_file/news_img_1.jpg"></a></div><div class="news-panel"><strong><a href="/news/' + item.id + '">' + item.title + '</a></strong><p class="detail"><span>' + item.content + '</span><a href="/news/' + item.id + '">[详细]</a></p><p class="read-push">发布时间：<span>' + item.createTime + '</span></p></div></div></div>';
                      $("#main_news_list").append(html);
                    });

                    reset_span_text();
                  }
                  else{
                    $("#main_news_list").append('<blockquote class="layui-elem-quote layui-quote-nm">暂无产品数据</blockquote>');
                  }
                }
                else{
                      layer.msg(res.message)
                    }
            }
          });
        }
      });
<% endblock %>